package com.mycompany.app.hr.tna.model;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * private static int[] itemLength = new int[] { 6, // clock_name, 6, //
 * clock_id, 1, // clock_record_type, 10, // emp_gid, 10, // punch_date, 5, //
 * punch_time_mm, 11, // punch_session, 1, // process_z_record, 5, //
 * process_start_date, 1, // process_record_type, 5, // process_running_date,
 * 10, // process_pin_no, 5, // process_punch_time, 5, //
 * process_real_punch_time, //10, // process_department_code, }; punch_time =
 * punch_date + process_real_punch_time;
 * 
 * 
 * 
 * Business Logic:
 * How to determine Punch In/Out?
 * 
 * 
 * 
 * @author Shawn.guo
 */
@Entity
@Table(name = "tna_punch_clock")
public class PunchClock {

    @Id
    @Column(name = "punch_clock_id")
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;

    // basic data
    private String gid;

    @Column(name="punch_time")
    //2008-10-24 18:31:00
    private Date punchTime;

    // import track
    @Column(name="import_time")
    private Date importTime;
    
    @Column(name="import_source")
    private String importSource;

    // process track
    @Column(name="process_time")
    private Date processTime;

    /**
     * 1--not processed 2--processed 3--no need process (future date's
     * data(judge by date, don't include time); 4--no need TA management
     * employee)
     * 
     * after import, process and match those records which status=1
     */
    @Column(name="process_status")
    private String processStatus;

    // unsaved
    // =======================================================
    @Transient
    private String clockName;

    @Transient
    private String clockId;

    @Transient
    private String clockRecordType;

    @Transient
    private String punchDate;

    @Transient
    private String punchTimeMM;

    @Transient
    private String punchSession;

    @Transient
    private String processZRecord;

    @Transient
    private String processStartDate;

    @Transient
    private String processRecordType;

    @Transient
    private String processRunningDate;

    @Transient
    private String processPinNo;

    @Transient
    private String processPunchTime;
    
    @Transient
    private String processRealPunchTime;

    // date format
    // =======================================================
    private static DateFormat df = new SimpleDateFormat("dd/MM/yyyy hh:mm");

    //construct
    // =======================================================
    public PunchClock() {

        super();
        this.importTime=new Date();
    }

    // =======================================================
    @Override
    public String toString() {

        return ToStringBuilder.reflectionToString(this,
                ToStringStyle.SHORT_PREFIX_STYLE);
    }

    // =======================================================

    public Integer getId() {

        return id;
    }

    public void setId(Integer id) {

        this.id = id;
    }

    public String getGid() {

        return gid;
    }

    public void setGid(String gid) {

        this.gid = gid;
    }

    public String getProcessStatus() {

        return processStatus;
    }

    public void setProcessStatus(String processStatus) {

        this.processStatus = processStatus;
    }

    public Date getPunchTime() throws ParseException {

        // return punchTime;

        this.punchTime = df.parse(new StringBuilder(this.punchDate).append(" ")
                .append(this.processRealPunchTime).toString());
        return punchTime;
    }

    public void setPunchTime(Date punchTime) {

        this.punchTime = punchTime;
    }

    public Date getImportTime() {

        return importTime;
    }

    public void setImportTime(Date importTime) {

        this.importTime = importTime;
    }

    public String getImportSource() {

        return importSource;
    }

    public void setImportSource(String importSource) {

        this.importSource = importSource;
    }

    public Date getProcessTime() {

        return processTime;
    }

    public void setProcessTime(Date processDate) {

        this.processTime = processDate;
    }

    public String getClockName() {

        return clockName;
    }

    public void setClockName(String clockName) {

        this.clockName = clockName;
    }

    public String getClockId() {

        return clockId;
    }

    public void setClockId(String clockId) {

        this.clockId = clockId;
    }

    public String getClockRecordType() {

        return clockRecordType;
    }

    public void setClockRecordType(String clockRecordType) {

        this.clockRecordType = clockRecordType;
    }

    public String getPunchDate() {

        return punchDate;
    }

    public void setPunchDate(String punchDate) {

        this.punchDate = punchDate;
    }

    public String getPunchTimeMM() {

        return punchTimeMM;
    }

    public void setPunchTimeMM(String punchTimeMM) {

        this.punchTimeMM = punchTimeMM;
    }

    public String getPunchSession() {

        return punchSession;
    }

    public void setPunchSession(String punchSession) {

        this.punchSession = punchSession;
    }

    public String getProcessZRecord() {

        return processZRecord;
    }

    public void setProcessZRecord(String processZRecord) {

        this.processZRecord = processZRecord;
    }

    public String getProcessStartDate() {

        return processStartDate;
    }

    public void setProcessStartDate(String processStartDate) {

        this.processStartDate = processStartDate;
    }

    public String getProcessRecordType() {

        return processRecordType;
    }

    public void setProcessRecordType(String processRecordType) {

        this.processRecordType = processRecordType;
    }

    public String getProcessRunningDate() {

        return processRunningDate;
    }

    public void setProcessRunningDate(String processRunningDate) {

        this.processRunningDate = processRunningDate;
    }

    public String getProcessPinNo() {

        return processPinNo;
    }

    public void setProcessPinNo(String processPinNo) {

        this.processPinNo = processPinNo;
    }

    public String getProcessPunchTime() {

        return processPunchTime;
    }

    public void setProcessPunchTime(String processPunchTime) {

        this.processPunchTime = processPunchTime;
    }

    public String getProcessRealPunchTime() {

        return processRealPunchTime;
    }

    public void setProcessRealPunchTime(String processRealPunchTime) {

        this.processRealPunchTime = processRealPunchTime;
    }

}
